<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/11
 * Time: 14:59
 */

namespace App\Http\Controllers\Admin;


use App\Http\Logics\Admin\MenuLogic;
use App\Http\Traits\MenuTrait;
use App\Http\Controllers\BaseController;
class MenuController extends BaseController
{
    use MenuTrait;

    /**
     * 获取菜单列表(通过parent_id判断父菜单子菜单)
     * @return string
     */
    public function getYiiccaMenuList()
    {
        $parent_id = $this->parent_id;
        $limit = $this->limit;
        $type = $this->type;
        $name = $this->name;
        $data = [
            'parent_id' => $parent_id,
            'limit' => $limit,
            'type' => $type,
            'name' => $name
        ];
        $response = MenuLogic::getYiiccaMenuList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 获取菜单列表(通过parent_id判断父菜单子菜单)
     * @return string
     */
    public function getMiniProgramMenuList()
    {
        $parent_id = $this->parent_id;
        $limit = $this->limit;
        $type = $this->type;
        $name = $this->name;
        $has_qrcode = $this->has_qrcode;
        $data = [
            'parent_id' => $parent_id,
            'limit' => $limit,
            'type' => $type,
            'name' => $name,
            'has_qrcode' => $has_qrcode
        ];
        $response = MenuLogic::getMiniProgramMenuList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 获取所有菜单列表
     * @return string
     */
    public function getAllMenuList()
    {
        $response = MenuLogic::getAllMenuList();
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 创建菜单
     * @return string
     */
    public function createMenu()
    {
        $parent_id = $this->parent_id;
        $name = $this->name;
        $path = $this->path;
        $type = $this->type;
        $icon = $this->icon;
        $data = [
            'parent_id' => $parent_id,
            'name' => $name,
            'path' => $path,
            'type' => $type,
            'icon' => $icon
        ];
        $response = MenuLogic::createMenu($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 删除菜单
     * @return string
     * @throws \Exception
     */
    public function deleteMenu()
    {
        $id =  $this->id;
        $data = [
            'id' => $id
        ];
        $response = MenuLogic::deleteMenu($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 更新菜单
     * @return string
     */
    public function updateMenu()
    {
        $id = $this->id;
        $name = $this->name;
        $path = $this->path;
        $type = $this->type;
        $icon = $this->icon;
        $data = [
            'id' => $id,
            'name' => $name,
            'path' => $path,
            'type' => $type,
            'icon' => $icon

        ];
        $response = MenuLogic::updateMenu($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function setMenuIcon()
    {
        $icon_file = $this->icon_file;
        $data = [
            'icon_file' => $icon_file
        ];
        $response = MenuLogic::setMenuIcon($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 获取菜单列表(通过parent_id判断父菜单子菜单)
     * @return string
     */
    public function getMenuList()
    {
        $parent_id = $this->parent_id;
        $limit = $this->limit;
        $type = $this->type;
        $name = $this->name;
        $data = [
            'parent_id' => $parent_id,
            'limit' => $limit,
            'type' => $type,
            'name' => $name
        ];
        $response = MenuLogic::getMenuList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function setMenuHasQrcode()
    {
        $menu_id = $this->menu_id;
        $data = [
            'menu_id' => $menu_id
        ];
        $response = MenuLogic::setMenuHasQrcode($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function getMenuAuthList()
    {
        $menu_id = $this->menu_id;
        $limit = $this->limit;
        $data = [
            'menu_id' => $menu_id,
            'limit' => $limit
        ];
        $response = MenuLogic::getMenuAuthList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function setMenuAuth()
    {
        $menu_id = $this->menu_id;
        $auth_id = $this->auth_id;
        $data = [
            'menu_id' => $menu_id,
            'auth_id' => $auth_id
        ];
        $response = MenuLogic::setMenuAuth($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function setMenuRootMenu()
    {
        $menu_id = $this->menu_id;
        $data = [
            'menu_id' => $menu_id
        ];
        $response = MenuLogic::setMenuRootMenu($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function deleteMenuAuth()
    {
        $id = $this->id;
        $data = [
            'id' => $id
        ];
        $response = MenuLogic::deleteMenuAuth($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}